package net.sf.jOpinionPoll.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

@Entity
@Table(name = "questao")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "questao_tipo_id", discriminatorType = DiscriminatorType.STRING, length = 2)
@DiscriminatorValue("DS")
@NamedQueries({
		@NamedQuery(name = "Questao.fetch.findById", query = "SELECT q FROM Questao q WHERE q.id = :id"),
        @NamedQuery(name = "Questao.findAll", query = "SELECT q FROM Questao q"),
        @NamedQuery(name = "Questao.count", query = "SELECT COUNT(q) FROM Questao q")
         })
public class Questao implements Serializable {
	private static final long serialVersionUID = -4107211210730770904L;
	
	private int id;
    private String descricao;
    private Date data;
    
    public Questao() {
    }
    
    public Questao(String descricao) {
    	this(descricao, null);
    }
    
    public Questao(String descricao, Date data) {
    	setDescricao(descricao);
    	setData(data);
    }
    
    @Id
    @Column(name = "id")
    @TableGenerator(
            name="questaoGen",
            table="sequence_generator_table",
            pkColumnName="gen_key",
            pkColumnValue="questao_id",
            valueColumnName="gen_value",
            allocationSize=50,
            initialValue=0)
    @GeneratedValue(
            strategy=GenerationType.TABLE,
            generator="questaoGen")
    public int getId() {
        return this.id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    
    @Column(name = "descricao", nullable = true, length = 255)
    public String getDescricao() {
        return this.descricao;
    }
    
    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }
    
    @Column(name = "data", nullable = false)
    public Date getData() {
        return this.data;
    }
    
    public void setData(Date data) {
        this.data = data;
    }
    
    @Override
    public int hashCode() {
        return getId();
    }
    
    @Override
    public boolean equals(Object o) {
        if (o == null || !(o instanceof Questao) || !o.getClass().getName().equals(this.getClass().getName()))
        	return false;
        
        if (getId() != 0)
	        return (getId() == ((Questao)o).getId());
        
        return this == o;
    }
    
    @Override
    public String toString() {
        return this.getClass().getName() + "[pk=" + getId() + "]";
    }
}